
#include "game.h"
void menu()
{
    printf("##########################\n");
    printf("#######     1.PVE    #####\n");
    printf("#######     2.PVP    #####\n");
    printf("#######     0.EXIT    #####\n");
    printf("##########################\n");
}
void game1()
{
    char ret=0;//接收ISwin()的返回值
    char board[ROW][COL]={0};
    //初始化棋盘
    INTboard(board,ROW ,COL);
    //打印棋盘
    displayboard(board,ROW,COL);
    //playermove()      //玩家下棋
    //computermove()    //电脑下棋
    while(1) //条件判断
    {
        playermove(board,ROW,COL);
        displayboard(board,ROW,COL);
        //判断输赢 赢了就结束 跳出循环
        ret=ISwin(board,ROW,COL);
         if(ret=='q')
            {
                printf("电脑获胜\n");
                break;
            }
        else if(ret=='p')
            {
                printf("玩家获胜\n");
                break;
            }
        else if(ret=='e')
            {
                printf("平局\n");
                break;
            }
        computermove(board,ROW,COL);
        displayboard(board,ROW,COL);
        //判断输赢 赢了就结束 跳出循环
        ret=ISwin(board,ROW,COL);
        if(ret=='q')
            {
                printf("电脑获胜\n");
                break;
            }
        else if(ret=='p')
            {
                printf("玩家获胜\n");
                break;
            }
        else if(ret=='e')
            {
                printf("平局\n");
                break;
            }
    }
    displayboard(board,ROW,COL);
}
void game2()
{
    char ret=0;//接收ISwin()的返回值
    char board[ROW][COL]={0};
     //初始化棋盘
    INTboard(board,ROW ,COL);
    //打印初始棋盘
    displayboard(board,ROW,COL);
    while(1)
    {
        //玩家一下棋 打印棋盘
        //玩家二下棋 打印棋盘
        //判断输赢
        playermove(board,ROW,COL);
        displayboard(board,ROW,COL);
        ret=ISwin(board,ROW,COL);
         if(ret=='q')
            {
                printf("玩家一获胜\n");
                break;
            }
        else if(ret=='p')
            {
                printf("玩家二获胜\n");
                break;
            }
        else if(ret=='e')
        {   
            {
                printf("平局\n");
                break;
            }
        }
        playertwomove(board,ROW,COL);
        displayboard(board,ROW,COL);
        ret=ISwin(board,ROW,COL);
         if(ret=='q')
            {
                printf("玩家二获胜\n");
                break;
            }
        else if(ret=='p')
            {
                printf("玩家一获胜\n");
                break;
            }
        else if(ret=='e')
        {
            {
                printf("平局\n");
                break;
            }
        }
    }
}
int main()
{
    srand((unsigned int)time(NULL));//时间戳 生成随机数字
    int input=0;
    do
    {
        menu();
        printf("请选择：->\n");
        scanf("%d",&input);
        switch(input)
        {
            case 1:
                game1();
                break;
            case 0:
                printf("退出游戏\n");
                break;
            case 2:
                game2();
                break;
            default:
                printf("请输入正确的数字哦！！\n");
                break;
        }
    } while (input);
    return 0;
}